class Solution(object):
    def maxDistToClosest(self, seats):
        """
        :type seats: List[int]
        :rtype: int
        """
        n = len(seats)
        left = [0] * n
        right = [0] * n
        time = - 1
        for i in range(n):
            if seats[i] == 0:
                if time >= 0:
                    time += 1
                    left[i] = time
            else:
                time = 0
        for i in range(n - 1, -1, -1):
            if seats[i] == 0:
                if time >= 0:
                    time += 1
                    right[i] = time
            else:
                time = 0
        max_len = - float('inf')
        for i in range(n):
            if left[i]:
                if right[i]:
                    dist = min(left[i], right[i])
                    max_len = max(max_len, dist)
                else:
                    max_len = max(left[i], max_len)
            else:
                if right[i]:
                    max_len = max(right[i], max_len)
        return max_len




data = Solution()
seats = [1, 0, 0, 0, 1, 0, 1]
print(data.maxDistToClosest(seats))
